import 'dart:convert';


import '../parse_factory.dart';
import '../rule.dart';

class PutRule extends Rule {
  Map<String, Rule> ruleMap;

  PutRule(this.ruleMap);

  @override
  String toString() {
    String string = "";
    ruleMap.forEach((key, value) {
      string += "{key:$key , value:$value},";
    });
    return "{ruleMap : $string}";
  }
}

class PutParser extends IParser<PutRule> {
  PutParser(PutRule rule) : super(rule);

  @override
  Future<String> getString(String content, {Map<String, dynamic>? valueMap}) async {
    if (valueMap != null) {
      for (var entry in rule.ruleMap.entries) {
        valueMap.putIfAbsent(
            entry.key, () => ParseFactory.getParser(entry.value).getString(content, valueMap: valueMap));
      }
    }
    return '';
  }

  @override
  Future<List<String>> getStringList(String content, {Map<String, dynamic>? valueMap}) async {
    if (valueMap != null) {
      for (var entry in rule.ruleMap.entries) {
        valueMap.putIfAbsent(
            entry.key, () => ParseFactory.getParser(entry.value).getString(content, valueMap: valueMap));
      }
    }
    return [];
  }
}
